Use case: HASH process using SHA1 algorithm in IT mode ¶
Sequence diagram ¶
Code snippet ¶
|
HAL1 |
HAL2 |
|---|---|
/* This example is used with HASH processing mode */
uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x5f, 0x45, 0x56, 0x41, 0x4c};
uint8_t Sha1output[20]={0};
/* HASH Initialization and configuration */
hhash.Init.DataType = HASH_DATATYPE_8B;
HAL_HASH_Init(&hhash);
/* Process with oneshot HASH computing SHA1 algorithm */
HAL_HASH_SHA1_Start_IT(&hhash, Msg65_Input, 65, Sha1output);
/* Process with multi-buffer updating to compute SHA1 algorithm */
HAL_HASH_SHA1_Accmlt_IT(&hhash, Msg65_Input, 60);
/* Wait for input completion callback */
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_READY);
/* Feed the last input data buffer to the peripheral and retrieve the digest */
HAL_HASH_SHA1_Accmlt_End_IT(&hhash, Msg65_Input+60, 5, Sha1output);
/* Wait for digest computation completed callback */
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_READY);
/* De-initialization */
HAL_HASH_DeInit(&hhash);
|
/* This example is used with HASH processing */
uint8_t Msg65_Input[65] __attribute__ ((aligned (128)))= {
0x52, 0x43, 0x31, 0x5f, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65,
0x61, 0x50, 0x72, 0x6f, 0x6a, 0x65,0x63, 0x74, 0x5f, 0x53,
0x46, 0x55, 0x61, 0x45, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
0x73, 0x61,0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x2d, 0x45, 0x56, 0x41, 0x4c, 0x61, 0x45, 0x57, 0x41, 0x52,
0x4d, 0x61, 0x53, 0x54, 0x4d, 0x33, 0x32, 0x32, 0x78, 0x47,
0x5f, 0x45, 0x56, 0x41, 0x4c};
uint8_t Sha1output[20]={0};
uint32_t sha1output_size;
/* HASH Initialization */
HAL_HASH_Init(&hhash, HAL_HASH);
/* Configure SHA1 algorithm */
hash_cfg.data_swapping = HAL_HASH_DATA_SWAP_BYTE;
hash_cfg.algorithm = HAL_HASH_ALGO_SHA1;
HAL_HASH_SetConfig(&hhash, &hash_cfg);
/* Process with oneshot HASH computing SHA1 algorithm */
HAL_HASH_Compute_IT(&hhash, Msg65_Input, 65, Sha1output,
20, &sha1output_size);
/* Process with multi-buffer updating to compute SHA1 algorithm */
HAL_HASH_Update_IT(&hhash, Msg65_Input, 60);
/* Wait for input completion callback */
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
/* Feed the last input data buffer to the peripheral */
HAL_HASH_Update_IT(&hhash, Msg65_Input+60, 5);
/* Wait for input completion callback */
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
/* Retrieve the digest */
HAL_HASH_Finish(&hhash, Sha1output, 20, &sha1output_size, 1000);
/* Wait for digest computation completed callback */
while (HAL_HASH_GetState(&hhash) != HAL_HASH_STATE_IDLE);
/* De-initialization */
HAL_HASH_DeInit(&hhash);
|
Key changes ¶
HAL2 uses unified interrupt APIs (compute/update/finish) and uses configuration functions to select the algorithm.
HAL2 uses different completion callbacks (input and digest completion) and supports multi-buffer HMAC in IT mode.



